package xyz.xtt.schedule.constants;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @author huqibo
 * 
 *         资产类型枚举
 */
public enum AssetTypeEnum {
	/**
	 * 地皮
	 */
	LAND(0, "地皮", "ground"),
	/**
	 * 经营证
	 */
	BUSINESS_CERTIFICATE(1, "经营证", "certificate"),
	/**
	 * 元宇宙资产
	 */
	METAVERSE(2, "元宇宙资产", "metaverse"),
	/**
	 * 聊天
	 */
	CHAT(3, "聊天", "chat"),
	/**
	 * 店铺
	 */
	SHOP(4, "店铺", "shop"),
	/**
	 * 商品
	 */
	GOODS(5, "商品", "goods"),
	/**
	 * 竞猜
	 */
	EXCEPT(6, "竞猜", "except"),
	/**
	 * 头像
	 */
	PFPS(7, "头像", "pfps"),
	/**
	 * 元素
	 */
	ELEMENT(8, "元素", "element"),
	/**
	 * 权益
	 */
	INTEREST(9, "权益", "interest"),

	/**
	 * 摄影
	 */
	PHOTO(10, "摄影", "photo"),
	/**
	 * 音乐
	 */
	MUSIC(11, "音乐", "music"),

	/**
	 * 设计
	 */
	DESIGN(12, "设计", "design"),;

	private int code;
	private String desc;
	private String groupType;

	/**
	 * 构造函数
	 * 
	 * @param code
	 * @param desc
	 * @param groupType
	 */
	AssetTypeEnum(int code, String desc, String groupType) {
		this.code = code;
		this.desc = desc;
		this.groupType = groupType;
	}

	public int code() {
		return code;
	}

	public String desc() {
		return desc;
	}

	public String groupType() {
		return groupType;
	}

	public static boolean checkType(String checkType) {
		return Arrays.asList(AssetTypeEnum.values()).stream().anyMatch(x -> Objects.equals(x.name(), checkType));
	}

	public static AssetTypeEnum convert(String checkType) {
		return Arrays.asList(AssetTypeEnum.values()).stream().filter(x -> Objects.equals(x.name(), checkType)).findFirst().orElse(null);
	}

	public static AssetTypeEnum queryConvert(Integer checkType) {
		return Arrays.asList(AssetTypeEnum.values()).stream().filter(x -> Objects.equals(x.code(), checkType)).findFirst().orElse(null);
	}

	public static List<Integer> queryNftTypes(String type) {
		return Optional.ofNullable(type).filter(StringUtils::isNotBlank).map(String::toUpperCase).map(x -> {
			AssetTypeEnum convert = AssetTypeEnum.convert(x);
			return Objects.isNull(convert) ? Lists.<Integer>newArrayList() : Arrays.asList(convert.code());
		}).orElseGet(() -> AssetTypeEnum.queryNftTypes());
	}

	public static List<Integer> queryNftTypes() {
		return Arrays
				.asList(AssetTypeEnum.EXCEPT.code(), AssetTypeEnum.PFPS.code(), AssetTypeEnum.ELEMENT.code(), AssetTypeEnum.INTEREST.code(), AssetTypeEnum.PHOTO
						.code(), AssetTypeEnum.MUSIC.code(), AssetTypeEnum.DESIGN.code());
	}

}